﻿using System;
namespace Producers.Rr.Xtee.Riik.Ee.Producer.Rr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RR411Response", Namespace="http://producers.rr.xtee.riik.ee/producer/rr", Target=typeof(RR411Response))]
    public class RR411ResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IRR411Response clazz;
        
        public RR411ResponseSerializer(IRR411Response clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("Isikukood");
            if (clazz.Isikukood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikukood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikukood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("MaakonnaKood");
            if (clazz.MaakonnaKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MaakonnaKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MaakonnaKood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("VallaKood");
            if (clazz.VallaKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.VallaKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : VallaKood");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("AsulaKood");
            if (clazz.AsulaKood!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.AsulaKood))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AsulaKood");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isikukood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR411Response>Isikukood");
                }
                clazz.Isikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikukood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR411Response>Isikukood", Reader.LocalName);
            }
            if (Reader.LocalName=="MaakonnaKood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR411Response>MaakonnaKood");
                }
                clazz.MaakonnaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("MaakonnaKood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR411Response>MaakonnaKood", Reader.LocalName);
            }
            if (Reader.LocalName=="VallaKood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR411Response>VallaKood");
                }
                clazz.VallaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("VallaKood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR411Response>VallaKood", Reader.LocalName);
            }
            if (Reader.LocalName=="AsulaKood") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RR411Response>AsulaKood");
                }
                clazz.AsulaKood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("AsulaKood")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>RR411Response>AsulaKood", Reader.LocalName);
            }
        }
    }
}
